#ifndef _MCMC_MODELSUPERVISOR
#define _MCMC_MODELSUPERVISOR

#include "mcmcParticle.h"
#include "mcmcRegionModel.h"
#include "mcmcMap.h"
#include "mcmcBottomupCue.h"
#include "mcmcFaceModel.h"

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// model supervisor that guids each region to choose a type of model
class MCMC_ModelSupervisor
{
public:
	// construction & destruction
	MCMC_ModelSupervisor();
	~MCMC_ModelSupervisor();

	inline	MCMC_Layer_Regions* LayerRegion(void);
	virtual MCMC_Particle* Particle(const int model_type);
	virtual void	Set(MCMC_Map_2Layers &map, MCMC_Particle &particle1,  MCMC_FilterResp &respFilter, const MCMC_SegSetting& setting);
	virtual void	InitRegionModels(void);
	virtual double	GetPdf(MCMC_Model *pmodel);
	virtual void	FitAllRegionParms(void);

	inline  void	ChangeMapPointer(MCMC_Map_2Layers &map){pmap=&map;};
	inline	bool	IsColorImage(void){return bcolor;};
	
	virtual void	ChooseModel(mcmcMatrix<int> &mx_label, const int num_label, irmm_Rect &bound, MCMC_Model* pmodels[]);
	virtual void	RecomputePosteriorRegions(LinkList<int> &list_region_ids);
	virtual void	RecomputePosteriorRegions(LinkList<int> &list_region_ids, MCMC_PixelSet &list_pixels_old,
											  MCMC_PixelSet &list_pixels_new);
	//------
	virtual int		PrepareModelType(RF& rf, LinkList<int> &list_aregions, LinkList<int> *plist_types_to_consider=NULL);
	virtual double	ProposeModelType(int &imodel, LinkList<int> &list_aregions, LinkList<int> *plist_types_to_consider=NULL);
	virtual double	QProposeModelType(int imodel, LinkList<int> &list_aregions, LinkList<int> *plist_types_to_consider=NULL);
	
	virtual MCMC_RegionModel *ProposeModel(LinkList<int> &list_aregions, LinkList<int> *plist_types_to_consider=NULL);

	int		ToModelType(int toc);
	int		ToCueType(int imodel);

	bool    *GetSelectedModelSign(){ return p_sign;	} // add by wtf
	
	virtual MCMC_RegionModel* CreateAndComputeModel(int imodel, LinkList<int> &list_aregions);

protected:

	virtual MCMC_Model*	SelectModelType(mcmcMatrix<int> &mx_label, const int nlabel, irmm_Rect &bound);

protected:
	MCMC_Map_2Layers	*pmap;
	MCMC_Particle		*pparticle_gauss;
	MCMC_FilterResp		*prespFilter;
	MCMC_FaceParticles	*face_particles;

	MCMC_ImageBtmupCues	bottomup_cues;

	bool                p_sign[NUM_MODEL_TYPE+1];

private:
	bool				bcolor;
	double				q_model_gauss;
	double				q_model_mixgauss;
	double				q_model_delta;
	double				q_model_texture;
	double				q_model_surface;
};

inline MCMC_Layer_Regions* MCMC_ModelSupervisor::LayerRegion(void)
{
	if (pmap == NULL)
		return NULL;
	else
		return pmap->LayerRegion();
}

#endif
